package com.bluesky.jwf.component;

import com.bluesky.jwf.component.event.EventHandler;

public class Button extends Component {
	public static String EVENT_CLICK = "click";

	private com.bluesky.javawebbrowser.domain.html.tags.form.input.Button button;

	// private String caption;

	@Override
	public void init(String html) {
		super.init(html);

		eventHandlers.put(EVENT_CLICK, null);

		button = (com.bluesky.javawebbrowser.domain.html.tags.form.input.Button) loadByJwfClass("button");

	}

	public String getText() {
		return button.getValue();
	}

	public void setText(String text) {
		button.setValue(text);
	}

	public boolean isDisabled() {
		return button.isDisabled();
	}

	public void setDisabled(boolean disabled) {
		button.setDisabled(disabled);
	}

	@Override
	public void setId(String id) {
		super.setId(id);
		button.setName(getId() + "_button");

	}

	public void setClickHandler(EventHandler handler) {

		if (handler != null) {
			button.setOnClick(String.format("_oum_post(this,'%s','click')",
					getId()));
		} else
			button.setOnClick("");

		eventHandlers.put(EVENT_CLICK, handler);
	}

}
